import axios from 'axios';
import qs from 'qs';
const ajax = function(config = {method: 'post', url: '/', timeout: 3000, data: {}, action: ''}){
    return axios({
        method: config.method || 'post',
        url: config.url,
        timeout: config.timeout,
        data: qs.stringify({
            action: config.action,
            data: JSON.stringify(config.data)
        })
    }).then(function (response) {
        let data = response.data;
        let currentUrl = encodeURIComponent(location.href);
        if(data.resultCode === '9990'){
            location.replace('/login.html?redirect='+currentUrl)
        }else{
            return response.data
        }
    })
};
export default ajax;
